package ch.doublet.jw.pubdownloader.repository;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;

import org.glassfish.jersey.jackson.JacksonFeature;

import ch.doublet.jw.pubdownloader.Response;
import ch.doublet.jw.pubdownloader.config.ConfigurationBundle;

public class PublicationRepositoryImpl implements PublicationRepository {

	public Object getPublication() throws Exception {

		UriBuilder uri = ConfigurationBundle.getRepoUri();
		Client client = ClientBuilder.newClient();
		WebTarget target = client.target(uri).queryParam("issue", "20120901")
				.queryParam("output", "json").queryParam("pub", "wp")
				.queryParam("langwritten", "E").register(JacksonFeature.class);

		Invocation buildGet = target.request()
				.accept(MediaType.APPLICATION_JSON_TYPE).buildGet();
		// Future<javax.ws.rs.core.Response> submit = buildGet.submit();
		Response bean = buildGet.invoke(Response.class);
		return bean;

	}

}
